# _*_ coding : utf-8 _*_
# @Time: 2024/7/16 16:18
# @Author : 石文帅	
# @File : LoginInterface
# @Project : python-interface-automation
from common import BasePage


class LoginInterface(object):

    def __init__(self, url):
        self.url = url

    def login(self, account, password):
        '''
        封装登录的Interface
        :param account: 用户名
        :param password: 密码
        :return:
        '''
        method = 'post'
        url = self.url + '/blade-auth/token'
        payload = {
            'account': account,
            'password': password,
            'loginType': 'STATION'
        }
        headers = {"Authorization": "Basic c2FiZXI6c2FiZXJfc2VjcmV0"}
        return BasePage.send_method(url=url, method=method, data=payload, headers=headers)

    def get_headers(self, account, password):
        '''
        封装获取请求头
        :param account:
        :param password:
        :return:
        '''
        result = self.login(account, password)
        token = BasePage.get_keyword(result, 'accessToken')
        #return {"Blade-Auth": "bearer " + token}
        return "bearer " + token

    def info_login(self, account, password):
        '''
        获取用户信息
        :param account:
        :param password:
        :return:
        '''
        method = 'post'
        url = self.url + '/blade-auth/token'
        result = self.get_headers(account, password)
        return BasePage.send_method(url=url, method=method, headers=result)


if __name__ == '__main__':
    login = LoginInterface("http://192.168.0.114:20099")

    #    print(login.login("cscsadmin","Rvy84+X1D9udHFybAMCv3zM80Rmd/FdIqfcwOzywKu0YC1sYWhV+7v8ydCzjZnxqjbOC6Q0ExF/ywbrG5YdOXUdhrYDsvuG2npVrJ+lTfcNOAXnWKQLP6A25J1zqxrmTxtBhbIGK1cBvaarOyNN3RMaKpE4Bfd+imRxz6jqCKnY="))
    headers = login.get_headers("cscsadmin",
                                "Rvy84+X1D9udHFybAMCv3zM80Rmd/FdIqfcwOzywKu0YC1sYWhV+7v8ydCzjZnxqjbOC6Q0ExF/ywbrG5YdOXUdhrYDsvuG2npVrJ+lTfcNOAXnWKQLP6A25J1zqxrmTxtBhbIGK1cBvaarOyNN3RMaKpE4Bfd+imRxz6jqCKnY=")
    #    print(login.info_login("cscsadmin","Rvy84+X1D9udHFybAMCv3zM80Rmd/FdIqfcwOzywKu0YC1sYWhV+7v8ydCzjZnxqjbOC6Q0ExF/ywbrG5YdOXUdhrYDsvuG2npVrJ+lTfcNOAXnWKQLP6A25J1zqxrmTxtBhbIGK1cBvaarOyNN3RMaKpE4Bfd+imRxz6jqCKnY="))

    print(headers)
